var app = angular.module( 'module.devup');
    app.controller('UploadController', UploadController);
UploadController.$inject = ['$scope','$http','DevupService','FileUpload','$state'];
function UploadController($scope, $http,DevupService,FileUpload,$state) {
    var vm = this;
    $scope.uploadImg = '';
    vm.upload=upload;
    vm.goShop=goShop;
    vm.goNotes=goNotes;
    vm.devInfo = {};
    vm.complete = complete;
    ////////////////////////////

    $(function(){
        $(".input-fileup").on("change","input[type='file']",function(){
            var filePath=$(this).val();
            if(filePath.indexOf("jpg")!=-1 || filePath.indexOf("png")!=-1){
                $(".fileerrorTip1").html("").hide();
                var arr=filePath.split('\\');
                var fileName=arr[arr.length-1];
                $(".showFileName1").html(fileName);
            }else{
                $(".showFileName1").html("");
                $(".fileerrorTip1").html("您未上传文件，或者您上传文件类型有误！").show();
                return false
            }
        })
    })
//
       $(function () {
            var str;
            $('#upload_file').change(function() { //<input type="file" name="" multiple="multiple" id="fil">
                str = $(this).val();
//              console.log($(this).val());
                var arr = str.split('\\'); //注split可以用字符或字符串分割,这里是分割成三个长度，找到长度对应的下标
//              console.log(arr)
                var name = arr[arr.length - 1]; //这就是要取得的图片名称
//              console.log(name);
                console.log($(".upload_file_text").text(name));

            })

        })

    /* 点击上传*/
    vm.t=true
    function upload(info) {
        if ($("#upload_file").val()==''){
            alert("上传不能为空")}else {
            FileUpload.uploadFileToUrl(info.packageAddress).then(function (data) {
                vm.devInfo.url = data.data.faddress;
                vm.devInfo.crc32 = data.data.crc32;
                $("#complete").removeAttr('disabled');
                alert("上传成功");
            },function(error){
                $scope.massage="上传失败";
                console.log("error",error)
                alert("上传失败")
            })
        }

    };
   /*点击确定上传*/

   function complete() {
       DevupService.updatedev(vm.devInfo, function (success) {
           $scope.massage="上传成功";
           alert("上传成功")

       }, function (error) {
           alert("上传失败")
       })

   }
   /*点击跳转*/
   function goNotes() {
       $state.go("updateNotes");
   }
    function goShop() {
        $state.go("shopList");
    }








}